package com.algo.sort;

import org.junit.Test;

import java.util.LinkedList;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class MaoPao {

    @Test
    public void test2(){
        String s="}}";
        test(s);
    }

    public void test(String s){
       if(s!=null&&s.length()==0){
           return;
       }
       if(s.length()%2!=0){
           throw new IllegalArgumentException();
        }

       LinkedList<Character> stack = new LinkedList<>();
       for(int i=0;i<s.length();i++){
            Character c=s.charAt(i);
            if(c=='['||c=='('||c=='{'){
                stack.push(c);
            }else {
                Character a = stack.poll();
                if(a==null||(c==']'&&a!='[')||(c==')'&&a!='(')||(c=='}'&&a!='{')){
                    throw new IllegalArgumentException();
                }
            }
       }
       if(stack.size()!=0){
           throw new IllegalArgumentException();
       }



    }
}
